package com.zhang.zhangapp.view.mine;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.zhang.zhangapp.R;
import com.zhang.zhangapp.application.MApplication;
import com.zhang.zhangapp.utils.DataCleanManager;
import com.zhang.zhangapp.utils.T;
import com.zhang.zhangapp.view.BaseAppCompatActivityActivity;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

/**
 * Created by 罗肖 on018/3/28.
 */

@ContentView(R.layout.activity_setting)
public class SettingActivity extends BaseAppCompatActivityActivity {


    @ViewInject(R.id.setting_cash_size)
    TextView cacheText;
    @ViewInject(R.id.setting_login_out)
    TextView loginOutText;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
        try {
            cacheText.setText(DataCleanManager.getTotalCacheSize(this));
            loginOutText.setEnabled(true);
        }catch (Exception e){

        }
    }

    @Event(type= View.OnClickListener.class,value = {R.id.setting_login_out,R.id.setting_feedback,R.id.setting_about_us,
    R.id.setting_cash_size,R.id.setting_problem,R.id.setting_user_agreement,R.id.action_bar_left_image})
    private void onClick(View view){
        switch (view.getId()){
            case R.id.action_bar_left_image:
                this.finish();
                break;
            case R.id.setting_login_out:
                loginOut();
                break;
            case R.id.setting_feedback:{
                Intent intent = new Intent(this,BackUsActivity.class);
                startActivity(intent);
            }
                break;
            case R.id.setting_about_us:{
                Intent intent = new Intent(this,AboutUsActivity.class);
                startActivity(intent);
            }
                break;
            case R.id.setting_cash_size:
                clearCache();
                break;
            case R.id.setting_problem:
                break;
            case R.id.setting_user_agreement:
                break;
        }
    }


    /*
    清楚缓存
     */
    private void clearCache(){
        try {
            DataCleanManager.clearAllCache(this);
            cacheText.setText(DataCleanManager.getTotalCacheSize(this));
        }catch (Exception e){

        }
    }

    /*
    退出登录
     */
    private void loginOut(){
        MApplication.getInstance().loginOut();
        T.showShort(this,"退出成功");
        loginOutText.setEnabled(false);
        this.finish();
    }
}
